package club.adger.mapper.impl;

import club.adger.entity.Student;
import club.adger.mapper.StudentMapper;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Adger
 * @Date: 2020/08/27/15:55
 * @controller 控制器（注入服务）
 *
 * @service 服务（注入dao）
 * 主要用来进行业务的逻辑处理
 *
 * @repository（实现dao访问）
 * 即DAO组件
 */
@Repository
public class StudentMapperImpl implements StudentMapper {

    private static Map<Long,Student> studentMap;

    static {
        studentMap = new HashMap<>();
        studentMap.put(1L,new Student(1L,"Adger",20));
        studentMap.put(2L,new Student(2L,"刘杰",21));
        studentMap.put(3L,new Student(3L,"Adger",22));
    }

    @Override
    public Collection<Student> findAll() {
        return studentMap.values();
    }

    @Override
    public Student findById(long id) {
        return studentMap.get(id);
    }

    @Override
    public void saveOrUpdate(Student student) {
        studentMap.put(student.getId(),student);
    }

    @Override
    public void deleteById(long id) {
        studentMap.remove(id);
    }
}
